package userBean;

import java.util.List;

import models.Usuario;
import dao.UsuarioDAO;
import Controller.SessionUtil;
import org.primefaces.event.SelectEvent;

public class Administrador {
	
	
	private Usuario selected_user=null;

	public int logueado(){
		if(SessionUtil.getCargo().equalsIgnoreCase("Administrador")){
			return 1;
		}
		else{
			return 0;
		}
	}
	
	public void welcome(){
		selected_user=null;
		SessionUtil.redirectTo("/administrador/welcome.xhtml");
	}
	
	public void list_users(){
		SessionUtil.redirectTo("/administrador/list_users.xhtml");
	}
	
	public List<Usuario> obtener_usuarios(){
		return UsuarioDAO.getListUsers();
	}
	
	public Usuario getSelected_user() {
		return selected_user;
	}

	public void setSelected_user(Usuario selected_user) {
		this.selected_user = selected_user;
	}

	public void onRowSelect(SelectEvent event){
		selected_user = (Usuario)event.getObject();
	}
	
	public void onRowUnselect(SelectEvent event){
		
	}
	
	public void New_user(){
		selected_user=null;
		SessionUtil.redirectTo("/administrador/new_user.xhtml");
	}
	
	public void area_trabajo(){
		selected_user=null;
		SessionUtil.redirectTo("/administrador/area_trabajo.xhtml");
	}
	
	public void perfil(){
		selected_user=null;
		SessionUtil.redirectTo("/administrador/perfil.xhtml");
	}
	
	public void cambiar_password(){
		selected_user=null;
		SessionUtil.redirectTo("/administrador/cambiar_password.xhtml");
	}
	
	public void logout(){
		selected_user=null;
		SessionUtil.closeSession();
		SessionUtil.redirectTo("/home/welcome.xhtml");
	}
}
